// firstPackage/pages/liveModule/applyLiveList/applyLiveList.js
import { queryLiveList } from "../../../../service/user_service"
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    themeStyle: "",
    switchArr: [
      {
        title: "直播计划",
        key: "1",
      },
      {
        title: "历史直播",
        key: 2,
      },
    ],
    exStatus: 0,//审核状态
    liveType: 1,//1:直播计划，2:历史直播
    liveList: [

    ],
    showImgVideo: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (app.globalData.themeStyle) {
      this.setData({
        themeStyle: app.globalData.themeStyle
      })
    }
    this.queryLiveList();
  },
  queryLiveList() {
    wx.showLoading();
    queryLiveList(this.data.liveType).then(res => {
      wx.hideLoading();
      console.log("JJLog:查询到的直播列表:" + JSON.stringify(res));
      if (res.code == 200) {
        this.setData({
          liveList: res.data || []
        })
      }
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({
        title: '查询失败',
        icon: "none"
      })
      console.error("JJLog:queryLiveList", err);
    })
  },

  //切换房源对应状态
  switchAction(e) {
    let index = e.currentTarget.dataset.index;
    let item = e.currentTarget.dataset.item;
    this.setData({
      exStatus: index,
      liveType: item.key
    })
    this.queryLiveList();

  },
  //跳转到直播间
  pushToRoom(e) {
    let item = e.currentTarget.dataset.item;
    if (item.liveStatus == 102 && item.examineStatus == 1) {
      wx.showToast({
        title: '直播申请审核中,暂时无法开始直播',
        icon: "none",
        duration: 3000,
      })
      return;
    }
    wx.navigateTo({
      url: "plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=" + item.roomId
    })
  },

  //跳转到发布直播申请:
  pushToPublish() {
    wx.navigateTo({
      url: '/firstPackage/pages/liveModule/applyLiveRoom/applyLiveRoom',
    })
  },

  //弹出更多:
  morePopAction() {
    this.setData({
      showImgVideo: true
    })
  },
  popupHide() {
    this.setData({
      showImgVideo: false
    })
  },






})